home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Source / MiscMergeKit / _MiscMergeAskCommand.m < prev    next >
Encoding:
Text File  |  1995-07-11  |  2.2 KB  |  76 lines

  1. //
  2. //    _MiscMergeAskCommand.m -- "ask" merge command implementation
  3. //        Written by Don Yacktman Copyright (c) 1995 by Don Yacktman.
  4. //                Version 1.0.  All rights reserved.
  5. //        This notice may not be removed from this source code.
  6. //
  7. //    This object is included in the MiscKit by permission from the author
  8. //    and its use is governed by the MiscKit license, found in the file
  9. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  10. //    for a list of all applicable permissions and restrictions.
  11. //    
  12.  
  13.  
  14. #import <misckit/miscmerge.h>
  15. #import "_MiscMergeAskCommand.h"
  16. #import "_MiscMergeQuery.h"
  17.  
  18. @implementation _MiscMergeAskCommand
  19.  
  20. static MiscString *myKey = nil;
  21.  
  22. - parseFromString:(MiscString *)aString
  23. {
  24.     MISC_Merge_Cond_Op operator;
  25.     if (!myKey) {
  26.         myKey = [MiscString new];
  27.         [myKey setStringValue:"ask"];
  28.     }
  29.     [self eatKeyWord:myKey from:aString isOptional:NO];
  30.     value1 = [self getArgumentStringFrom:aString toEnd:NO];
  31.     operator = [self getConditionalFrom:aString];
  32.     if (operator != MISC_MCO_EQUAL) {
  33.         id tempString = [MiscString
  34.                 newWithString:"Set requires operator to be an =."];
  35.         [self error_conditional:tempString];
  36.         [tempString free];
  37.         value2 = [MiscString new];
  38.     }
  39.     value2 = [self getPromptFrom:aString toEnd:YES];
  40.     [value1 trimWhiteSpaces];
  41.     return self;
  42. }
  43.  
  44.  
  45. - executeForMerge:(MiscMergeEngine *)aMerger
  46. {
  47.     _MiscMergeQuery *query = [_MiscMergeQuery new];
  48.     id question = [MiscString new];
  49.     if (([value2 length] < 1) || ![value2 stringValue]
  50.                 || (!(*([value2 stringValue])))) {
  51.         // This needs to be localized!
  52.         [question setFromFormat:
  53.                 "Please enter the value for the %s field:", value1];
  54.     } else { // Use the question that was given to us
  55.         [question setStringValue:[value2 stringValue]];
  56.     }
  57.     [query setQuestion:[question stringValue]];
  58.     [query showWindow:self];
  59.     if ([query status] == MISC_QueryAccepted) {
  60.         id temp  = [MiscString new];
  61.         [temp setStringValue:[query stringValue]];
  62.         [temp trimWhiteSpaces];
  63.         [aMerger setSymbol:value1 toValue:temp];
  64.         [temp free];
  65.     } else if ([query status] == MISC_QueryCancelled) {
  66.         // Cancelling is treated as an "omit"!
  67.         [aMerger abortMerge];
  68.         [question free];
  69.         return nil;
  70.     }
  71.     [question free];
  72.     return self;
  73. }
  74.  
  75. @end
  76.